package com.ruoyi.mobile.api;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageSerializable;
import com.ruoyi.common.core.domain.AjaxResults;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.qsng.domain.KMyExchange;
import com.ruoyi.qsng.domain.KUsers;
import com.ruoyi.qsng.service.IKUsersService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 排行榜
 *
 * @author gk
 * @date 2023-06-19
 */
@Api(tags = "排行榜")
@RestController
@RequestMapping
public class RankingController {

    @Autowired
    private IKUsersService kUsersService;


    @ApiOperation(value = "排行榜")
    @GetMapping("/weixin/ranking/list")
    public AjaxResults<List<KUsers>> exchangeList(
            @RequestParam(required = false, defaultValue = "1") Integer pageNum,
            @RequestParam(required = false, defaultValue = "10") Integer pageSize)
    {
        PageHelper.startPage(pageNum, pageSize);
        List<KUsers>  kUsersList =kUsersService.selectKUsersOrderByIntegral();
        //处理排行
        int i;
        if(pageNum==1){
            i=1;
        }else {
            i=(pageNum-1)*pageSize+1;
        }
        for (KUsers kUsers: kUsersList) {
            kUsers.setRank((long) i);
            i++;
        }
        return AjaxResults.success(new PageSerializable<>(kUsersList));
    }
}
